# !/usr/bin/env python
# -*- coding:utf-8 -*-
import time

class userModel(object):
    def __init__(self, structuredData):
        self.city = structuredData.get("house_city")
        self.uid = "dmp_%d" % (structuredData.get("user_id"))
        self.appName = structuredData.get("appName")
        self.imei = structuredData.get("imei")
        self.idfa = structuredData.get("idfa")
        self.event = self._event( structuredData.get("source_id") )
        self.create_time = self._create_time(structuredData.get("created_at"))
        self.user_type = self._user_type(self.event)

    def getDictData(self):

        try:
            #todo 必填字段验证

            return self.__dict__

        except Exception, e:
            pass


    def _create_time(self, data):
        return int(time.mktime(data.timetuple()))

    def _event(self, data):
        data = int(data)
        evalDict = {
            1 : {"name":"dsp", "short_name":"dsp"},
            2: {"name": "泰岳", "short_name": "taiyue"},
        }

        return evalDict[data]['short_name']


    def _user_type(self, data):
        # user_type(10:来自诸葛找房，1：来自大数据联盟, 2:来自dsp)
        typeDist = {
            "dsp":1,
        }

        return typeDist.get(data, 2)

